package org.lee.common.core.service;

import cn.dev33.satoken.stp.StpInterface;
import org.lee.common.core.enums.UserTypeEnum;
import org.lee.common.core.vo.request.LoginUser;
import org.lee.common.util.LoginHelper;
import org.noear.solon.annotation.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * sa-token 权限管理实现类
 *
 * @author Lion Li
 */
@Component
public class SaPermissionImpl implements StpInterface {

    /**
     * 获取菜单权限列表
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        LoginUser loginUser = LoginHelper.getLoginUser();
        UserTypeEnum userType = loginUser.getUserType();
        if (userType == UserTypeEnum.PC) {
            return new ArrayList<>(loginUser.getMenuPermission());
        } else if (userType == UserTypeEnum.MOBILE) {
            // TODO: 其他端 自行根据业务编写
        }
        return new ArrayList<>();
    }

    /**
     * 获取角色权限列表
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        LoginUser loginUser = LoginHelper.getLoginUser();
        UserTypeEnum userType = loginUser.getUserType();
        if (userType == UserTypeEnum.PC) {
            return new ArrayList<>(loginUser.getRolePermission());
        } else if (userType == UserTypeEnum.MOBILE) {
            // TODO: 其他端 自行根据业务编写
        }
        return new ArrayList<>();
    }
}
